<?php
//require_once 'TVB/Auth/Auth.php';
require_once 'TVB/Config/ConfigReader.php';
require_once 'TVB/Config/ConfigReaderFactory.php';
require_once 'TVB/DB/DBConnPool.php';
require_once 'TVB/DB/DBFarmConnPool.php';
require_once 'TVB/DB/DBConnPoolFactory.php';

//$userId = TVBGetAuthUserFromCookie();
//if (!$userId) {
//	http_send_status(405);
//	exit;
//}

$uri = $_REQUEST['uri'];
$download = isset($_REQUEST['download']) ? $_REQUEST['download'] : FALSE;
$file = "/data/image_infrastructure/image/{$uri}";
$filename = basename($file);
if (file_exists($file)) {
	$fp = fopen($file, 'rb');

	$size = getimagesize($file);
	$mimeType = $size['mime'];
	
	// send the right headers
	header("Content-Type: {$mimeType}");
	header("Content-Length: " . filesize($file));

	if ($download) {
		header('Content-Disposition: attachment; filename="' . $filename . '"');
	}

	// dump the picture and stop the script
	fpassthru($fp);
	exit;
}

echo '';
?>
